﻿using System;
using System.Text;
using System.Drawing;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;

public static partial class NativeAOT
{
    [UnmanagedCallersOnly(EntryPoint = "hmgs")]
    public static unsafe double hmgs(IntPtr f_x_ptr)
    {
        f_x = Marshal.GetDelegateForFunctionPointer<delegatefunc_x>(f_x_ptr);

        return hmgs();
    }

    /// <summary>
    /// 埃尔米特_高斯求积法
    /// f计算被积函数值f(x)的函数名。
    /// </summary>
    /// <returns>函数返回积分值。</returns>
    public static unsafe double hmgs()
    {
        int i;
        double x, g;
        double[] t = new double[5] {
            -2.02018200,-0.95857190, 0.0,0.95857190,2.02018200
        };
        double[] c = new double[5]{
            1.181469599,0.9865791417, 0.9453089237,0.9865791417,1.181469599
        };
        g = 0.0;
        for (i = 0; i <= 4; i++)
        {
            x = t[i];
            g = g + c[i] * f_x(x);
        }
        return (g);
    }

    /*
    // 埃尔米特_高斯求积法例
      int main()
      { 
          double hmgsf(double);
          cout <<"g = " <<hmgs(hmgsf) <<endl;
          return 0;
      }
    // 计算被积函数值
      double hmgsf(double x)
      { 
          double y;
          y=x*x*exp(-x*x);
          return(y);
      }
    */
}

